<?php
//验证管理员的身份
include_once 'checkAdmin.php';
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .main {
            width: 80%;
            margin: 0 auto;
            text-align: center;
        }

        .main ul {
            width: 90%;
            margin: 0 auto;
            text-align: center;
        }

        h2 {
            text-align: center;
            font-size: 15px;
        }

        h2 a {
            margin-right: 15px;
            color: navy;
            text-decoration: none;
        }

        h2 a:last-child {
            margin-right: 0;
        }

        h2 a:hover {
            color: crimson;
            text-decoration: none;
        }

        /*.current{*/
        /*    color: cyan;*/
        /*}*/
        /*.logged{*/
        /*    font-size: 16px;*/
        /*    color: darkgrey;*/

        /*}*/
        /*.logged .logout{*/
        /*    margin-left: 20px;*/
        /*    margin-bottom: 15px;*/
        /*}*/
        /*.logged .logout a{*/
        /*    color: cornflowerblue;*/
        /*    text-decoration: none;*/
        /*}*/
        /*.logged .logout a:hover{*/
        /*    text-decoration: underline;*/

        tr:hover{background-color: azure;}

        .trClick2{background-color: white;}
        .trClick1{background-color: navy;}
    </style>
</head>
<body>
<div class="main">
    <?php include_once 'nav.php';
    include_once 'conn.php';
    include_once 'page.php';

    $sql = "select count(id) as total from info "; //使用count()聚合函数统计总记录数
    $result = mysqli_query($conn, $sql);//执行上面的sql语句
    $info = mysqli_fetch_array($result);//将结果集格式化变为数组
    $total = $info['total'];//得到记录总数
    $perPage = 2;   //每页总数
    paging($total, $perPage);//paging每页滚动
    $page = $_GET['page'] ?? 1;//
    $sql = "select * from info order by id desc limit $firstCount, $perPage";
    $result = mysqli_query($conn, $sql);


    ?>
    <table border="1" cellspacing="0" cellpadding="10" style="border-collapse: collapse" align="center" width="100%">
        <tr>
            <td>序号</td>
            <td>用户名</td>
            <td>性别</td>
            <td>邮箱</td>
            <td>是否为管理员</td>
            <td>操作</td>
            <td>爱好</td>
        </tr>
        <?php
//        页数管理
        $i = ($page - 1) * $perPage + 1;
        while ($info = mysqli_fetch_array($result)) {
            ?>
            <tr onclick="if(this.className == 'trClick2'){this.className = 'trClick1'}else{this.className = 'trClick2'}" class="trClick2">
                <td><?php echo $i; ?> </td>
                <td><?php echo $info['username']; ?></td>
                <td><?php echo $info['sex'] ? '男' : '女'; ?></td>
                <td><?php echo $info['email']; ?></td>
                <td><?php echo $info['admin'] ? '是' : '否'; ?></td>
<!--                获取name的名字-->
                <td><a href="modify.php?id=4&username=<?php echo $info['username']?>&&source=admin&page=<?php echo $page?>">修改资料</a>
<!--                    设置管理员代码-->
                    <?php
                    if($info['username']<>'admin'){?>
                    <a href="javascript:del(<?php echo $info['id'];?>,
                '<?php echo $info['username'];?>')">删除会员</a>
                    <?php
                }else{
                    echo '<span style="color: darkgrey">删除会员 </span>';
                }?>

                    <?php if ($info['admin']) {
                        if ($info['username'] <> 'admin') {
                            ?>

                            <a href="setAdmin.php?action=0&id=<?php echo $info['id']; ?>">取消管理员</a>
                        <?php } else {
                            echo "<span style='color: darkgrey'>取消管理员</span>";
                        }
                    } else {
                        if ($info['username'] <> 'admin') {
                            ?>

                            <a href="setAdmin.php?action=1&id=<?php echo $info['id']; ?>">设置管理员</a>
                        <?php } else {
                            echo "<span style='color: darkgrey'>设置管理员</span>";
                        }
                        ?>

                    <?php } ?>

                </td>
                <td><?php echo $info['fav']; ?></td>
            </tr>
            <?php
            $i++;
        }

        ?>

    </table>
    <?php
    echo $pageNav;
    ?>
    <script>
//        删除管理员
     function del(id,name) {
            if(confirm('你确定是否删除：' + name + '?')){
                location.href='del.php?id=' + id + '&username=' + name
            }
     }
        //sql = "delect from info where id = $id
    </script>
</div>
</body>
</html>

